package steveshrader.budget.client.events;

import steveshrader.budget.shared.ExpenseProxy;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.web.bindery.requestfactory.shared.RequestContext;

/**
 * Begin editing an Expense.
 */
public class EditExpenseEvent extends GwtEvent<EditExpenseEvent.Handler> {
  public static final Type<Handler> TYPE = new Type<Handler>();

  /**
   * Handles {@link EditExpenseEvent}.
   */
  public interface Handler extends EventHandler {
    void startEdit(ExpenseProxy expense, RequestContext requestContext);
  }

  private final ExpenseProxy expense;
  private final RequestContext request;

  public EditExpenseEvent(ExpenseProxy expense) {
    this(expense, null);
  }

  public EditExpenseEvent(ExpenseProxy expense, RequestContext request) {
    this.expense = expense;
    this.request = request;
  }

  @Override
  protected void dispatch(Handler handler) {
    handler.startEdit(expense, request);
  }

  @Override
  public com.google.gwt.event.shared.GwtEvent.Type<Handler> getAssociatedType() {
    return TYPE;
  }
}
